package com.youhui.weixin.config;

import com.youhui.weixin.common.MythConfig;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * Created by https://github.com/kuangcp on 17-10-21  下午4:20
 *
 * @author kuangcp
 */
@ComponentScan("com.youhui.weixin.service.task")
@Configuration
@EnableAsync
public class TaskExecutorConfig implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(MythConfig.CORE_POOL_SIZE);
        taskExecutor.setMaxPoolSize(MythConfig.MAX_POOL_SIZE);
        taskExecutor.setQueueCapacity(MythConfig.QUEUE_CAPACITY);
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }
}
